package com.example.babybus.store

import android.app.Application
import android.content.Context
import android.content.SharedPreferences

object BabyBusStore {
    const val KEY_MAP_TYPE = "babybus_map_type"
    const val KEY_MAP_INDOOR = "babybus_map_indoor"
    const val KEY_MAP_TRAFFIC = "babybus_map_traffic"
    const val KEY_MAP_ZOOM = "babybus_map_zoom"
    // todo: more type

    private lateinit var sp: SharedPreferences

    fun init(application: Application) {
        sp = application.getSharedPreferences("babybus", Context.MODE_PRIVATE)
    }

    fun save(key: String, value: Boolean) {
        sp.edit().putBoolean(key, value).apply()
    }

    fun save(key: String, value: String) {
        sp.edit().putString(key, value).apply()
    }

    fun save(key: String, value: Int) {
        sp.edit().putInt(key, value).apply()
    }

    fun save(key: String, value: Long) {
        sp.edit().putLong(key, value).apply()
    }

    fun getBoolean(key: String, defaultValue: Boolean = false): Boolean {
        return sp.getBoolean(key, defaultValue)
    }

    fun getString(key: String, defaultValue: String = ""): String {
        return sp.getString(key, defaultValue)!!
    }

    fun getLong(key: String, defaultValue: Long): Long {
        return sp.getLong(key, defaultValue)
    }

    fun getInt(key: String, defaultValue: Int = 0): Int {
        return sp.getInt(key, defaultValue)
    }

    fun hasKey(key: String): Boolean {
        return sp.contains(key)
    }
}